package net.csdn.business.gateway.schedule;

import lombok.extern.slf4j.Slf4j;
import net.csdn.business.gateway.handler.GatewayRouteHandler;
import net.csdn.business.gateway.service.impl.RouteDefinitionCacheServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @ClassName RouteUpdateSchedule
 * @Description 内存中缓存的路由信息定时更新
 * @Author zhangyl
 * @Date 2023/4/6 09:57
 */
@Slf4j
@Component
public class RouteUpdateSchedule {

    @Autowired
    private GatewayRouteHandler gatewayRouteHandler;

    /**
     * @Author zhangyl
     * @Description 系统启动后，30分钟之后首次执行，然后1小时执行一次
     * @Date 10:01 2023/4/6
     * @Param
     * @return
     **/
    @Scheduled(initialDelay = 30*60*1000, fixedDelay = 60 * 60 * 1000)
    //@Scheduled(cron = "0 0 * * * ?")
    public void routeUpdate() {
        log.info("------gatway update route start------");
        gatewayRouteHandler.loadRouteConfig();
        log.info("------gatway update route end------");
    }
}